package code.extract;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class FileDealer {
	public static String getFileContent(String filename) throws IOException {
		File file = new File(filename);
		FileReader fr;
		BufferedReader br;
		String oneLine;
		StringBuffer sb = new StringBuffer();

		fr = new FileReader(file);
		br = new BufferedReader(fr);
		oneLine = br.readLine();

		while (oneLine != null) {
			sb.append(oneLine);
			sb.append("\n");
			oneLine = br.readLine();
		}

		return sb.toString();
	}
	
	public static String getFileContent(String filename, String encode) throws IOException {
		File file = new File(filename);
		FileInputStream fis;
		InputStreamReader isr;
		BufferedReader br;
		String oneLine;
		StringBuffer sb = new StringBuffer();

		fis = new FileInputStream(file);
		isr = new InputStreamReader(fis, encode);
		br = new BufferedReader(isr);
		oneLine = br.readLine();

		while (oneLine != null) {
			sb.append(oneLine);
			sb.append("\n");
			oneLine = br.readLine();
		}

		return sb.toString();
	}
}
